package com.agent.commons.config;


import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

@Slf4j
@Configuration
public class MqConfig {

    @Resource
    private RabbitTemplate rabbitTemplate;

    public MqConfig() {
        log.info("return机制设置成功!");
    }

    /**
     * 消息无法从交换机发送到队列，触发该回调
     */
    @PostConstruct
    public void initRabbitMq() {
        rabbitTemplate.setReturnsCallback(returned -> {
            log.error("监听到了消息return callback");
            log.debug("exchange:{}",returned.getExchange());
            log.debug("routingKey:{}",returned.getRoutingKey());
            log.debug("message:{}",returned.getMessage());
            log.debug("replyCode:{}",returned.getReplyCode());
            log.debug("replyText:{}",returned.getReplyText());
        });
    }
}
